import "./init/bmob.init.js"

const queryEvent = Bmob.Query('web_event');

/**
 * 保存用户信息至Bmob
 */
export function saveWebEvent(res, complete) {
    queryEvent.set("event", res.event || "")
    queryEvent.set("xpath", res.xpath || "")
    queryEvent.set("domHtml", res.domHtml || "")
    queryEvent.set("domText", res.domText || "")

    // 通用参数
    queryEvent.set("url", window.location.href)
    queryEvent.set("ua", navigator.userAgent)
    queryEvent.set("referrer", document.referrer)
    queryEvent.set("visitorId", window.visitorId || "")

    queryEvent.save().then(res => {
        console.log("保存结果", res)
        queryEvent.get(res.objectId).then(res => {
            console.log("查询结果", res)
        }).catch(err => {
            console.log(err)
        })
        complete && complete()
    }).catch(err => {
        console.log(err)
        complete && complete()
    })
}
